import VueI18n from 'vue-i18n';
import Vue from 'vue';
Vue.use(VueI18n);

function getAppLanguage() {
    // console.log("111222")
    let language,
        reg = /^zh-/i;
        // console.log("111222")
    let DEFAULT_LANGUAGE = 'zh-CN';
    if(localStorage && localStorage.getItem('AppLanuage')) {
        language = localStorage.getItem('AppLanuage');
    } else if (window.hilink && window.hilink.getAppLanguageSync) {
        language = window.hilink.getAppLanguageSync();
    } else if (navigator && navigator.language) {
        language = navigator.language;
    } else {
        language = DEFAULT_LANGUAGE;
    }   
    language = String(language).toLowerCase();
    language = reg.test(language) || language === 'bo-cn' ? 'zh-CN' : 'en-US';
    // console.log("111222")
    //return 'en-US';
    return language;
}


const i18n = new VueI18n({
    locale: getAppLanguage(),
    // locale: 'en-US',
    messages: {
        'zh-CN': require('./language/zh.json'),
        'en-US': require('./language/en.json')
    }
});
export default i18n;
